package cn.lanqiao.springboot.mapper;

import cn.lanqiao.springboot.entity.User;
import cn.lanqiao.springboot.vo.QueryUserVO;
import cn.lanqiao.springboot.vo.UserVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {

    List<User> selectAllUsers(QueryUserVO queryUserVO);

    @Insert("insert into system_user (user_name, password, email, create_time) values (#{userName}, #{password}, #{email}, #{createTime})")
    void insertUser(User user);

    @Delete("delete from system_user where user_id = #{userId}")
    void deleteUser(Integer userId);

    @Update("update system_user set user_name = #{userName}, password = #{password}, email = #{email} where user_id = #{userId}")
    void updateUser(User user);

    @Select("select su.user_id, su.user_name, sr.role_id, sr.role_name, su.password " +
            "from system_user su, system_user_role sur, system_role sr \n" +
            "where su.user_id = sur.user_id and sr.role_id = sur.role_id and su.user_name = #{userName}")
    UserVO checkUser(User user);
}
